package com.sc.admin.controller;

import com.sc.admin.common.annotation.Log;
import com.sc.admin.common.enums.BusinessTypeEnum;
import com.sc.admin.common.enums.ModuleEnum;
import com.sc.admin.common.result.PageResult;
import com.sc.admin.common.util.ExcelUtils;
import com.sc.admin.model.query.SysLoginInfoLogQuery;
import com.sc.admin.model.vo.SysLoginInfoExportVO;
import com.sc.admin.model.vo.SysLoginInfoVO;
import com.sc.admin.service.SysLoginInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@Tag(name = "08.登录信息日志表")
@RestController
@RequestMapping("/api/v1/logs/login")
@RequiredArgsConstructor
public class SysLoginInfoLogController {


    private final SysLoginInfoService sysLoginInfoService;

    /**
     * 列表请求
     * @param query 日志列表对象
     * @return 请求列表
     */
    @Operation(summary = "登录日志分页列表")
    @GetMapping("/page")
    public PageResult<SysLoginInfoVO> page(SysLoginInfoLogQuery query) {
        return PageResult.success(sysLoginInfoService.pageLog(query));
    }


    @Operation(summary = "导出登录日志")
    @GetMapping("/export")
    @Log(module = ModuleEnum.LOGIN_LOG, title = "导出登录日志", businessType = BusinessTypeEnum.EXPORT)
    public void exportUsers(SysLoginInfoLogQuery queryParams, HttpServletResponse response) throws IOException {
        List<SysLoginInfoExportVO> exportLogList = sysLoginInfoService.listExportLogs(queryParams);
        ExcelUtils.export(response, SysLoginInfoExportVO.class, exportLogList, "登录日志列表");
    }

}
